package com.zx.system.block.controller.system;

import com.zx.core.wrapper.PageWrapper;
import com.zx.core.wrapper.ResponseWrapper;
import com.zx.log.annotation.OperateLog;
import com.zx.system.block.param.DictTypeParam;
import com.zx.system.block.service.ISysDictTypeService;
import com.zx.system.block.vo.SysDictTypeVO;
import com.zx.validation.annotation.ParameterValidation;
import com.zx.validation.annotation.ParameterValidations;
import com.zx.validation.enums.ValidateRulesEnum;
import com.zx.validation.groups.Create;
import com.zx.validation.groups.Query;
import com.zx.validation.groups.StatusUpdate;
import com.zx.validation.groups.Update;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * description: 系统字典类型 <br>
 * create: 2025-11-18
 * </p>
 *
 * @author zhou xun
 */
@RestController
@RequestMapping("/dict/type")
@RequiredArgsConstructor
public class SysDictTypeController {
    private final ISysDictTypeService iSysDictTypeService;

    /**
     * 分页获取字典类型列表
     *
     * @param dictTypeParam 查询参数
     * @return {@link PageWrapper<SysDictTypeVO>}
     * @author zhou xun
     * @since 2025-11-18
     */
    @PreAuthorize("hasAuthority('system:dict:type:list')")
    @OperateLog(value = "分页获取字典类型列表")
    @PostMapping("/listByPage")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "字典类型参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Query.class})
    )
    public PageWrapper<SysDictTypeVO> listByPage(@RequestBody DictTypeParam dictTypeParam) {
        return iSysDictTypeService.selectDictTypeVOListByPage(dictTypeParam);
    }

    /**
     * 新增字典类型
     *
     * @param dictTypeParam 字典类型信息
     * @return {@link ResponseWrapper}
     * @author zhou xun
     * @since 2025-11-18
     */
    @PreAuthorize("hasAuthority('system:dict:type:add')")
    @OperateLog(value = "新增字典类型")
    @PostMapping("/addDictType")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "字典类型参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Create.class})
    )
    public ResponseWrapper addDictType(@RequestBody DictTypeParam dictTypeParam) {
        return iSysDictTypeService.addDictType(dictTypeParam);
    }

    /**
     * 编辑字典类型
     *
     * @param dictTypeParam 字典类型信息
     * @return {@link ResponseWrapper}
     * @author zhou xun
     * @since 2025-11-18
     */
    @PreAuthorize("hasAuthority('system:dict:type:edit')")
    @OperateLog(value = "编辑字典类型")
    @PutMapping("/editDictType")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "字典类型参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Update.class})
    )
    public ResponseWrapper editDictType(@RequestBody DictTypeParam dictTypeParam) {
        return iSysDictTypeService.editDictType(dictTypeParam);
    }

    /**
     * 修改字典类型状态
     *
     * @param dictTypeParam 字典类型参数
     * @return {@link ResponseWrapper}
     * @author zhou xun
     * @since 2025-11-18
     */
    @PreAuthorize("hasAuthority('system:dict:type:edit')")
    @OperateLog(value = "修改字典类型状态")
    @PutMapping("/editDictTypeStatus")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "字典类型参数", rules = {ValidateRulesEnum.OBJECT}, groups = {StatusUpdate.class})
    )
    public ResponseWrapper editDictTypeStatus(@RequestBody DictTypeParam dictTypeParam) {
        return iSysDictTypeService.editDictTypeStatus(dictTypeParam.getId(), dictTypeParam.getStatus());
    }

    /**
     * 删除字典类型
     *
     * @param dictTypeId 字典类型Id
     * @return {@link ResponseWrapper}
     * @author zhou xun
     * @since 2025-11-18
     */
    @PreAuthorize("hasAuthority('system:dict:type:remove')")
    @OperateLog(value = "删除字典类型")
    @DeleteMapping("/deleteDictType/{dictTypeId}")
    @ParameterValidations({
            @ParameterValidation(index = 0, desc = "字典类型Id", rules = {ValidateRulesEnum.NOT_NULL}, groups = {Update.class})
    })
    public ResponseWrapper deleteDictType(@PathVariable("dictTypeId") String dictTypeId) {
        return iSysDictTypeService.deleteDictType(dictTypeId);
    }
}